import { ref, computed, reactive } from "vue";
import { defineStore } from "pinia";
import _ from "lodash";

export const useTabStore = defineStore("tab", () => {
  const tabs = ref([
    { title: "首页", content: "", key: "/Basic/System/Index", closable: false,name:'SystemIndex' },
  ]);
  const tabKey = ref("");
  const AddTab = (obj) => {
    if (obj.key === "/") {
      return;
    }
    if (!_.some(tabs.value, { key: obj.key })) {
      tabs.value.push({ title: obj.title, key: obj.key, closable: true,name:obj.name });
    }
  };
  const SetTabKey = (key) => {
    tabKey.value = key;
  };
  const RemoveTab = (key) => {
    tabs.value = _.reject(tabs.value, { key: key });
  };
  const ClearTab = (app) => {
    if (app === "1") {
      tabs.value = [
        { title: "首页", content: "", key: "/Basic/System/Index", closable: false,name:'SystemIndex' },
      ];
    } else {
      tabs.value = [
        { title: "首页", content: "", key: "/Basic/System/Index", closable: false,name:'SystemIndex' },
      ];
    }
  };
  return { tabs, tabKey, AddTab, SetTabKey, RemoveTab, ClearTab };
});
